<template>
	<view class="content" style="">
		<view class="calendar" v-for="(item, index) in timeList" :key="index">
			<sign :dateString="item" :expand.sync="expand" :index="index" :selected="selected"></sign>
		</view>
		<mix-load-more :status="loading"></mix-load-more>
	</view>
</template>

<script>
import http from '@/common/request.js';
import { getCommonShareInfo } from '@/common/utils.js';
import Sign from '../personal/components/calendar-sign.vue';
import mixLoadMore from '@/components/mix-load-more/mix-load-more';
export default {
	onShareAppMessage() {
		return getCommonShareInfo()
	},
	components: {
		Sign,
		mixLoadMore
	},
	data() {
		return {
			expand: 0,
			signList: [],
			timeList: [],
			selected: [],
			loading: 0,
			pageNum: 1,
			pageSize: 10,
			isToday: false
		};
	},
	watch: {
		expand(index){
			this.detail(index)
		}
	},
	mounted() {
		this.list();
	},
	onReachBottom() {
		if (this.loading != 2) {
			this.list();
		}
	},
	methods: {
		list() {
			this.loading = 1;
			http('/api/cusUserInfo/getCheckDetailsDate', {
				data: {
					pageNum: this.pageNum,
					pageSize: this.pageSize
				},
				method: 'GET'
			}).then(
				result => {
					let data = result.data.times || [];
					this.timeList = this.timeList.concat(data); //进行数据的累加
					if (this.pageNum === 1) {
						this.detail(0);
					}
					if (data.length == this.pageSize) {
						this.pageNum++; //页数的++
						this.loading = 0;
					} else {
						this.loading = 2;
					}
					this.loading = this.timeList.length === 0 ? 3 : this.loading;
				},
				result => {
					this.loading = 0;
					uni.showToast({
						title: result.msg,
						icon: 'none'
					});
				}
			);
		},

		detail(index) {
			if(this.expand === -1 && this.expand === index) {
				return;
			}
			const time = this.timeList[index]
			http('/api/cusUserInfo/getCheckDetailsByCustomerId', {
				data: {
					queryTime: time
				},
				method: 'GET'
			}).then(
				result => {
					let data = result.data;
					const list = [];
					this.selected = [];
					data.forEach(item => {
						list.push({ date: item.createTime.split(' ')[0] });
					});
					this.selected = list;
				},
				result => {
					this.showLoading = false;
					uni.showToast({
						title: result.msg,
						icon: 'none'
					});
				}
			);
		}
	}
};
</script>

<style lang="less" scoped>
.content {
	min-height: 100vh;
	background: #f7f7f7;
	padding: 24rpx 28rpx;
	.calendar {
		overflow: hidden;
		margin-bottom: 24rpx;
	}
}
</style>
